package tableRelations.entity;

import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.OrderBy;

import org.hibernate.annotations.CreationTimestamp;
@Entity
public class Student {
	private Integer id;
	private String name;
	private String stuNum;
	private String sex;
	private TbClass tbClass;
	private List<Course> courses;

	public Student() {
		super();
	}

	public Student(Integer id, String name, String stuNum, String sex) {
		super();
		this.id = id;
		this.name = name;
		this.stuNum = stuNum;
		this.sex = sex;
	}

	@Id
	@GeneratedValue(strategy=GenerationType.IDENTITY)
	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}
	
	@Column(length=10)
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}
	
	@Column(length=12)
	public String getStuNum() {
		return stuNum;
	}

	public void setStuNum(String stuNum) {
		this.stuNum = stuNum;
	}
	
	@Column(length=2)
	public String getSex() {
		return sex;
	}

	public void setSex(String sex) {
		this.sex = sex;
	}
	
	@ManyToOne
	public TbClass getTbClass() {
		return tbClass;
	}

	public void setTbClass(TbClass tbClass) {
		this.tbClass = tbClass;
	}

	@ManyToMany
	@JoinTable(name="student_course",joinColumns= {@JoinColumn(name="student_id")},inverseJoinColumns= {@JoinColumn(name="course_id")})
	@OrderBy("id")
	public List<Course> getCourses() {
		return courses;
	}

	public void setCourses(List<Course> courses) {
		this.courses = courses;
	}
	
}
